<template>
  <div>
    <el-table v-loading="loading" :data="dataSource" :height="autoHeight" @row-click="handleRowClick">
      <el-table-column prop="scriptId" label="ID" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="scriptName" label="名称" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="scriptNote" label="备注" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="updateAt" label="更新日期" align="center"></el-table-column>
      <el-table-column label="操作" align="center" width="110px">
        <div v-if="!select" slot="header">
          <el-button type="primary" @click="visible = true" icon="el-icon-circle-plus-outline"></el-button>
        </div>
        <div slot-scope="scope">
          <template v-if="select">
            <el-button type="success" icon="el-icon-thumb" circle @click="$emit('rowSelect',scope.row)" title="选择"></el-button>
          </template>
          <template v-else>
            <el-button type="success" icon="el-icon-edit" circle @click="() => { entityInfo=$Util.copy(scope.row);visible=true}" title="编辑"></el-button>
            <el-button type="danger" icon="el-icon-delete" circle @click="removeData(scope.row, scope.$index)" title="删除"></el-button>
          </template>
        </div>
      </el-table-column>
    </el-table>
    <div class="lab-table-page">
      <div style="display: inline-flex">
        <el-pagination
            :disabled="loading"
            :current-page="pageInfo.page"
            :page-sizes="[5, 10, 15, 20, 50, 100]"
            :page-size="pageInfo.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="pageInfo.total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
        />
        <el-button-group style="padding: 2px 5px">
          <el-button icon="el-icon-refresh" title="刷新" :disabled="loading" @click="loadSource([])" />
        </el-button-group>
      </div>
    </div>

    <el-dialog :visible.sync="visible" title="数据库连接信息">
      <el-form label-position="right" label-width="80px">
        <el-form-item label="名称">
          <el-input v-model="entityInfo.scriptName" placeholder="脚本名称"/>
        </el-form-item>
        <el-form-item label="脚本类型" required>
          <el-select v-model="entityInfo.scriptTag" style="width: 100%">
            <el-option v-for="item in scriptTag" :key="item.value" :value="item.value" :label="item.label" />
          </el-select>
        </el-form-item>
        <el-form-item label="脚本内容" required>
          <el-input v-model="entityInfo.scriptBody" type="textarea" :autosize="{ minRows: 8, maxRows: 18}" placeholder="脚本内容"/>
        </el-form-item>
        <el-form-item label="脚本备注">
          <el-input v-model="entityInfo.scriptNote" type="textarea"  :autosize="{ minRows: 4, maxRows: 8}" placeholder="脚本备注"/>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-circle-check" type="success" @click="saveData(entityInfo)">{{ entityInfo.scriptId ? '更新' : '保存' }}</el-button>
          <el-button icon="el-icon-circle-close" type="info" @click="visible = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import IdeaTable from "@/mixins/IdeaTable";
import TableTable from "@/views/system/db/TableTable";

export default {
  name: "DbTable",
  components: {TableTable},
  mixins: [IdeaTable],
  props: {
    select: {
      type: Boolean,
      default: false
    }
  },
  computed:{
    autoHeight() {
      return this.select ? `300px` : `calc(100vh - 130px)`
    }
  },
  data() {
    return {
      scriptTag: [
        { value: 'store', label: '文件存储' },
        { value: 'process', label: '业务流程' },
      ]
    }
  },
  created() {
    this.queryUrl = '/dbScript/queryPage'
    this.saveUrl = '/dbScript/save'
    this.removeUrl = '/dbScript/delete/'
    this.rowKey = 'scriptId'
    this.loadSource()
  },
  methods: {
  }
}
</script>

<style scoped>

</style>
